<template>
	<view class="padding-top-sm">
		<view class="edgeInsetTop"></view>
		<view class="form margin-lr">
			<view class="order padding-tb-sm bg-white flex justify-between align-center">
				<view class="left">
					<text class="text-30 text-black">入驻人员</text>
				</view>
				<view class="right flex-sub flex justify-end align-center" @tap="$wanlshop.to(`/pages/Medical/treatment?source=3&order_id=${optionData.id}`)">
					<text class="name" v-if="treatment">{{treatment.name}}({{sex[treatment.sex]}})</text>
					<text class="wlIcon-fanhui2 margin-left-xs text-bold"></text>
				</view>
			</view>
			<!-- <view class="order padding-tb-sm bg-white flex justify-between align-center">
				<view class="left">
					<text class="text-30 text-black" style="width: 160rpx;">地址</text>
				</view>
				<view class="right">
					<text class="name" v-if="treatment">{{treatment.address}}</text>
				</view>
			</view> -->
			<view class="order padding-tb-sm bg-white flex justify-between align-center">
				<view class="left">
					<text class="text-30 text-black">姓名</text>
				</view>
				<view class="right">
					<text class="name" v-if="treatment">{{treatment.name}}</text>
				</view>
			</view>
			<view class="order padding-tb-sm bg-white flex justify-between align-center">
				<view class="left">
					<text class="text-30 text-black">联系电话</text>
				</view>
				<view class="right">
					<text class="name" v-if="treatment">{{treatment.mobile}}</text>
				</view>
			</view>
		</view>

		<view class="goods bg-white margin-lr margin-top-xs flex justify-between align-center" v-if="goodsData">
			<image :src="$wanlshop.oss(goodsData.image)" mode="aspectFill"></image>
			<view class="info">
				<view class="title text-cut-2">{{goodsData.title}}</view>
				<view class="center flex justify-between align-center">
					<view class="flex justify-start">
						<text class="text-price text-red">{{goodsData.price}}</text>
		
					</view>
					<uni-number-box :min="1" :value="num" @change="changeNum"></uni-number-box>
				</view>
				<view class="bottom">
					<text>合计</text>
					<text class="text-bold text-red text-price">{{sub_price}}</text>
				</view>
			</view>
		</view>
		
		<view class="bg-white margin-lr margin-tb-sm">
			<textarea class="padding-sm text-df" style="width: 100%;" v-model="memo" placeholder="如有特色要求，请给商家留言" />
		</view>
		<view class="safeAreaBottom"> </view>
		<view class="wanlian cu-bar tabbar solid-top foot text-df">
			<view class="flex justify-start align-center">
				<text class="wanl-gray">待支付</text>
				<text class="text-red" v-if="goodsData">{{ sub_price }}元</text>
			</view>
			<button v-if="loading" class="cu-btn lg bg-green margin-lr-bj">
				<text class="wlIcon-jiazai wlIconfont-spin margin-right-xs"></text> 提交中...
			</button>
			<button v-else @tap="addOrder" class="cu-btn lg bg-green margin-lr-bj text-bold text-lg"> 下单并支付 </button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			sex:{1:"男",2:'女'},
			order_type: '', // 类型
			loading: false,
			reload: false,
			token: '',
			optionData: {},
			addressData: {},
			orderData: {},
			goodsData: null,
			num: 0,
			sub_price: 0,
			memo: '',
			time: '请选择服务时间',
			sendDate: {
			    score: 0,
			    content: "",
				images: [],
			    contact: ""
			},
			gender: true,
			genderdata: 0,
			times: {
				date:'',
				time:'',
				id:''
			},
			treatment:null,
			hospital_id:'',
			hospital: '请选择医院'
		};
	},
	onLoad(option) {
		console.log("option",option)
		
		this.num = option.num
		this.loadData(option);
	},
	methods: {
		reloads(item) {
			this.hospital_id = item.id;
			this.hospital = item.title
		},
		getUsers(data) {
			this.treatment = data;
		},
		Gender(e) {
			if(e.detail.value == true){
				this.gender = true;
				this.genderdata = 0;
			}else{
				this.gender = false;
				this.genderdata = 1;
			}
		},
		setData(date,time,timestr,id) {
			this.times = {date:date,time:time,id:id}
			this.time = timestr
		},
		async getAddress(option) {
			this.optionData.address_id = option
			await uni.request({
				url: `/member/address/detail`,
				method:"POST",
				data: {
					id:option
				},
				success: res => {
					this.addressData = res.data;
				}
			})
		},
		async loadData(option) {
			//加载商品
				await uni.request({
					url: '/addons/nursing/api.index/detail',
					data: {
						id:option.id
					},
					method: 'POST',
					success: res => {
						this.goodsData = res.data;
						this.goodsData.title = res.data.sku[option.cur].name;
						this.goodsData.price = res.data.sku[option.cur].price;
						this.goodsData.asprice = res.data.sku[option.cur].asprice;
						this.goodsData.sku_id = res.data.sku[option.cur].id
						this.sub_price = this.$wanlshop.bcmul(this.goodsData.price, this.num);
					}
				});
			
		},
		// 提交订单
		async addOrder() {
			console.log("提交订单",this.treatment)
			console.log(this.goodsData)
			if(!this.treatment) {
				this.$wanlshop.msg('请选择服务人员')
				return false;
			}
			this.loading = true;
			// 提交订单数据data
				await uni.request({
					url: `/addons/nursing/api.order/add`,
					method: 'POST',
					data: {
						nursing_id: this.goodsData.id,
						document_id:this.treatment.id,
						quantity: this.num,
						sku_id: this.goodsData.sku_id,
						remark: this.memo,
					},
					success: res => {
						console.log("res",res)
						this.$wanlshop.to(`/pages/user/money/pay?type=nursing&id=${res.data}`);
						this.loading = false;
					},
					complete: () => {
						setTimeout(() => {
							this.loading = false;
						}, 1500);
					}
				});
		},
		// 修改数量
		changeNum(num){
			console.log(num)
			num = num == 0 ? 1 : num;
			this.num = num;
			// 计算价格
			this.sub_price = this.$wanlshop.bcmul(this.goodsData.price, num);
		},
		close(e){
		    this.sendDate.images.splice(e,1);
		},
	}
};
</script>

<style lang="less">
.wanlian,.safeAreaBottom {
	height: calc(128rpx + env(safe-area-inset-bottom)) !important;
}
.wanlian {
	justify-content: space-between !important;
	background-color: #fff !important;
	> view {
		margin-left: 34rpx;
		text {
			display: inline-block;
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			color: #333333;
			line-height: 44rpx;
			font-weight: 400;
			&:nth-child(1) {
				color: #333333;
			}
			&:nth-child(2) {
				color: red;
			}
		}
	}
	button {
		width: 326rpx;
		height: 72rpx;
		border-radius: 10rpx;
	}
}
.goods {
	padding: 26rpx 18rpx;
	border-radius: 10rpx;
	> image {
		width: 202rpx;
		height: 202rpx;
		border-radius: 6rpx;
	}
	.info {
		width: calc(100% - 234rpx);
		.title {
			font-size: 32rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: 400;
			color: #333333;
			line-height: 48rpx;
		}
		.center {
			font-size: 40rpx;
			line-height: 42rpx;
			margin-top: 18rpx;
			> text {
				color: #E31F1F;
				// font-weight: bold;
				font-size: 40rpx;
			}
			/deep/.uni-numbox {
				border: none;
				padding: 0;
				justify-content: center;
				align-items: center;
				.uni-numbox__minus,.uni-numbox__plus {
					background-color: transparent;
					width: 22rpx;
					text {
						display: inline-block;
						color: #000000;
					}
				}
				.uni-numbox__value {
					width: 42rpx;
					height: 42rpx;
					background: #F4F4F4;
					border-radius: 4rpx;
					margin: 0 10rpx;
				}
			}
		}
		.bottom {
			display: flex;
			justify-content: flex-end;
			align-items: center;
			margin-top: 38rpx;
			text {
				display: inline-block;
				&:nth-child(1) {
					font-size: 20rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #666666;
					line-height: 28rpx;
				}
				&:nth-child(2) {
					font-size: 34rpx;
					font-family: DIN-Bold, DIN;
					font-weight: bold;
					color: #E31F1F;
					line-height: 48rpx;
					margin-left: 12rpx;
				}
			}
		}
	}
}

.form {
	padding: 0 20rpx;
	background-color: #fff;
	border-radius: 10rpx;
	.order {
		border-bottom: 1rpx solid rgba(182,182,182,0.3);
		&:last-child {
			border: none;
		}
		.right {
			text {
				&.name {
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 400;
					color: #444444;
				}
			}
		}
	}
}
	.switch-sex {
		transform:scale(0.7);
	}
</style>
